/**
 * 
 */
package design_pattern.chainOfResponsibility;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @author linzq
 * 
 */
public class DrumBeater {

  static Player firstPlayer;

  static boolean stop = false;

  private Timer timer;

  /**
   * @param args
   */
  public static void main(String[] args) {
    DrumBeater drumBeater = new DrumBeater();
    JiaMu jiaMu = new JiaMu(null);
    jiaMu.setSuccessor(new JiaShe(new JiaZheng(new JiaBaoYu(new JiaHuan(jiaMu)))));
    drumBeater.startBeating(10);
    firstPlayer = jiaMu;
    firstPlayer.handle();
  }

  public void startBeating(int stopInSecods) {
    System.out.println("Drum beating starting...");
    timer = new Timer();
    timer.schedule(new StopBeatingReminder(), stopInSecods * 1000);
  }

  class StopBeatingReminder extends TimerTask {

    @Override
    public void run() {
      System.out.println("Drum beating stoping...");
      stop = true;
      timer.cancel();
    }

  }

}
